package com.example.mapper;

import com.example.entity.Video;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface VideoMapper {
    @Select("<script>" +
            "SELECT * FROM video " +
            "LIMIT #{offset}, #{limit}" +
            "</script>")
    List<Video> selectVideosByPage(@Param("offset") int offset, @Param("limit") int limit);

    @Select("SELECT COUNT(*) FROM video")
    int countVideos();

    @Select("<script>" +
            "SELECT * FROM video WHERE 1=1 " +
            "<if test='titlePart != null and titlePart != \"\"'>AND title LIKE CONCAT('%', #{titlePart}, '%')</if> " +
            "LIMIT #{offset}, #{limit}" +
            "</script>")
    List<Video> selectVideosByTitlePart(@Param("offset") int offset, @Param("limit") int limit, @Param("titlePart") String titlePart);

    @Select("<script>" +
            "SELECT COUNT(*) FROM video WHERE 1=1 " +
            "<if test='titlePart != null and titlePart != \"\"'>AND title LIKE CONCAT('%', #{titlePart}, '%')</if>" +
            "</script>")
    int countVideosByTitlePart(@Param("titlePart") String titlePart);
}
